import {
  ActionType,
  ModalForm,
  PageContainer,
  ProColumns,
  ProFormDigit,
  ProFormSelect,
  ProFormText,
  ProTable
} from "@ant-design/pro-components";
import {Button, Form} from "antd";
import React, {useRef, useState} from "react";
import {EditOutlined, PlusOutlined, SettingFilled} from "@ant-design/icons";
import {globalLoadTableApi, handleGloblApi} from "@/services/admin-api/globalApi";

type Customer = {
  customerId: number;
  customerNickName: string;
  customerSex: number;
  customerPhoneNumber: string;
  customerHeadImgUrl: string;
  customerWechatMiniAppOpenId: string;
  delFlag: boolean;
  createTime: string;
  createUserId: number;
  createUserName: string;
  updateTime: string;
  updateUserId: number;
  updateUserName: string;
};

const customerSex = [
  {label: '女', value: 0,},
  {label: '男', value: 1,},
]

export default () => {

  // const [modalOpen, handleModalOpen] = useState(false);
  // const [form] = Form.useForm();
  const actionRef = useRef<ActionType>();
  // const [currentRow, setCurrentRow] = useState<ProductType>();

  const columns: ProColumns<Customer>[] = [
    {title: 'ID', dataIndex: 'customerId', valueType: 'digit'},
    {title: '昵称', dataIndex: 'customerNickName', valueType: 'text'},
    {title: '性别', dataIndex: 'customerSex', valueType: 'select', fieldProps: {options: customerSex,}},
    {title: '电话', dataIndex: 'customerPhoneNumber', valueType: 'text'},
    {title: '头像', dataIndex: 'customerHeadImgUrl', valueType: 'text'},
    {title: 'openid', dataIndex: 'customerWechatMiniAppOpenId', valueType: 'text'},
    {title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '创建用户ID', dataIndex: 'createUserId', valueType: 'digit', hideInSearch: true,},
    {title: '创建用户', dataIndex: 'createUserName', valueType: 'text', hideInSearch: true,},
    {title: '更新时间', dataIndex: 'updateTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '更新用户ID', dataIndex: 'updateUserId', valueType: 'digit', hideInSearch: true,},
    {title: '更新用户', dataIndex: 'updateUserName', valueType: 'text', hideInSearch: true,},
    // {
    //   title: <SettingFilled/>,
    //   render: (_, record) => [
    //     <Button
    //       key={'edit_' + record.customerId} size="small" icon={<EditOutlined/>} type="primary"
    //       onClick={async () => {
    //         form.setFieldsValue({...record});
    //         handleModalOpen(true);
    //       }}
    //     />,
    //   ],
    //   valueType: 'option',
    // },
  ];

  return <PageContainer header={{title: '', breadcrumb: {},}}>
    <ProTable<Customer>
      columns={columns} actionRef={actionRef}
      search={{span: 4}}
      // headerTitle={
      //   <Button
      //     key="primary" type="primary" icon={<PlusOutlined/>} onClick={() => {
      //     handleModalOpen(true)
      //   }}/>
      // }
      request={async (param) => globalLoadTableApi('/customer/table', param)}
      rowKey={(record) => record.customerId}
      columnsState={{
        defaultValue: {
          delFlag: {show: false},
          createUserId: {show: false},
          updateUserId: {show: false}
        }
      }}/>

    {/*<ModalForm*/}
    {/*  modalProps={{destroyOnClose: true}} autoFocusFirstInput submitTimeout={15000}*/}
    {/*  width="400px" open={modalOpen} onOpenChange={handleModalOpen} form={form}*/}
    {/*  onFinish={async (value) => {*/}
    {/*    console.log('value = ', value);*/}
    {/*    let success = await handleGloblApi('/customer/saveOrUpdate', value)*/}

    {/*    if (success) {*/}
    {/*      actionRef.current?.reload();*/}
    {/*      return true*/}
    {/*    }*/}

    {/*  }}*/}
    {/*>*/}
    {/*  <ProFormDigit label="ID" name="customerId" hidden/>*/}
    {/*  <ProFormText label="昵称" rules={[{required: true}]} name="customerNickName"/>*/}
    {/*  <ProFormSelect label="性别" rules={[{required: true}]} name="customerSex" options={customerSex}/>*/}
    {/*  <ProFormText label="手机号" rules={[{required: true}]} name="customerPhoneNumber"/>*/}
    {/*  <ProFormText label="openid" rules={[{required: true}]} name="customerWechatMiniAppOpenId"/>*/}
    {/*</ModalForm>*/}

  </PageContainer>
}
